﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using wp8nop.ViewModel;
using System.Diagnostics;
using Coding4Fun.Toolkit.Controls;

namespace wp8nop
{
    public partial class DettaglioProdotto : PhoneApplicationPage
    {
        DettaglioProdottoViewModel vm;
        public DettaglioProdotto()
        {
            InitializeComponent();
            vm = (DettaglioProdottoViewModel)this.DataContext;
            this.Loaded += DettaglioProdotto_Loaded;
            img.Loaded += img_Loaded;
        }

        void DettaglioProdotto_Loaded(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("IsLoading true");
            vm.IsLoading = true;
        }

        void img_Loaded(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("IsLoading false");
            vm.IsLoading = false;
        }

        private void Acquista_Click(object sender, System.Windows.Input.GestureEventArgs e)
        {
            vm.AddToCart();
            ToastPrompt t = new ToastPrompt();
            t.Title = "Prodotto aggiunto al carrello";
            t.Show();
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Carrello.xaml", UriKind.Relative));
        }

        private void GoToHome_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }
    }
}